<template>
  <div class="alarm-box">
    <myTable
      :columns="columns"
      :dataSource="tableData"
      :total="total"
      @changePagination="getTableList"
    >
      <template #statusSlot="slotData">
        {{ slotData.scope.status == 1 ? "发生中" : "已解决" }}
      </template>
      <template #level="slotData">
        <span>{{ getLavelName(slotData.scope.alarmLevel) }}</span>
      </template>
    </myTable>
  </div>
</template>
<script>
import { queryRobotAlarmList } from "@/api/device.js";
export default {
  data() {
    return {
      total: 0,
      tableData: [],
      columns: [
        {
          title: "报警名称",
          dataIndex: "alarmTitle",
        },
        {
          title: "状态",
          dataIndex: "status",
          scopedSlots: {
            customRender: "statusSlot",
          },
        },
        {
          title: "等级",
          dataIndex: "alarmLevel",
          scopedSlots: {
            customRender: "level",
          },
        },
        {
          title: "电站",
          dataIndex: "stationName",
        },
        {
          title: "设备",
        },
        {
          title: "报警开始时间",
        },
        {
          title: "恢复时间",
        },
        // {
        //   title: "操作",
        //   scopedSlots: {
        //     customRender: "operation",
        //   },
        // },
      ],
      plainOptions: [
        {
          value: "1",
          label: "提示",
        },
        {
          value: "2",
          label: "警告",
        },
        {
          value: "3",
          label: "故障",
        },
      ],
    };
  },
  methods: {
    getTableList(pageMsg) {
      let alarm = {
        type: 6,
      };

      let requestPage = {
        page: 1,
        limit: 50,
      };
      if (pageMsg?.page) {
        requestPage.page = pageMsg.page;
        requestPage.limit = pageMsg.pageSize;
      }
      queryRobotAlarmList({ ...requestPage, alarm }).then((res) => {
        console.log(res);
        this.tableData = res.data;
        this.total = res.count;
      });
    },
    getLavelName(l) {
      let lavel = this.plainOptions.find((item) => {
        return item.value == l;
      });
      if (lavel) {
        return lavel.label;
      } else {
        return "--";
      }
    },
  },
  mounted() {
    this.getTableList();
  },
};
</script>
<style lang="less" scoped>
.alarm-box {
  box-sizing: border-box;
  padding: 16px;
}
</style>